//
//  NoVipCell.m
//  ChatForHot
//
//  Created by FLY on 2018/10/19.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "NoVipCell.h"
#import "NoVipModel.h"
@implementation NoVipCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.msgLab];
        [self.msgLab mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView);
            
            make.width.mas_lessThanOrEqualTo(HOTCHATUIWIDTH - 60);
            make.bottom.equalTo(self.contentView).offset(-7);
        }];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(HOTCHATtouchaction)];
        [self addGestureRecognizer:tap];
        
    }
    return self;
}


- (UILabel *)msgLab {
    if (_msgLab == nil) {
        _msgLab = [[UILabel alloc] init];
        _msgLab.font = [UIFont systemFontOfSize:13];
        _msgLab.textColor = HOTCHATHexColor(0x666666);
        _msgLab.numberOfLines = 0;
    }
    return _msgLab;
}

- (void)setModel:(NoVipModel *)model{
    _model = model;
    
    if (model.touchType >= 1) {
        
        NSString *mmstr = [NSString stringWithFormat:@"%@%@",NSLocalizedString(@"novip03", nil),model.msg];
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:mmstr];
        NSRange strRange = [mmstr rangeOfString:model.msg];//{0,[str length]};
        [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange];
        
        UIColor *bluecolor = [UIColor blueColor];
        [str addAttribute:NSForegroundColorAttributeName value:bluecolor range:strRange];
        
        self.msgLab.attributedText = str;
    }else{
        self.msgLab.text = model.msg;
    }
}

- (void)HOTCHATtouchaction{
    if (self.model.touchType == 1) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(HOTCHATpolicyAction)]) {
            [self.delegate HOTCHATpolicyAction];
        }
    }else if (self.model.touchType == 2){
        if (self.delegate && [self.delegate respondsToSelector:@selector(HOTCHATServiceAction)]) {
            [self.delegate HOTCHATServiceAction];
        }
    }
}

@end
